package ycj.learn.redis.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ycj.learn.redis.model.Res;
import ycj.learn.redis.model.User;
import ycj.learn.redis.service.IContactService;

import java.util.List;

@RestController
@RequestMapping("/contact")
public class ContactController {

    @Autowired
    IContactService contactService;


    @ApiOperation("获取")
    @GetMapping("/{id}")
    public Res fetchOne(@PathVariable Long id) {

        return Res.success(contactService.fetchOne(id)) ;
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public Res delOne(Long id) {

        return Res.success(contactService.delOne(id)) ;
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    public Res addOne(@RequestBody User user) {

        return Res.success(contactService.addOne(user)) ;
    }

    @ApiOperation("列出所有")
    @GetMapping("/list")
    public Res listAll() {

        return Res.success(contactService.listAll()) ;
    }

}
